package LeetCode.LeetCode2;

/**
 * 删除链表中的重复节点
 * @author lumin
 * @date 2022/03/28 17:20
 **/
public class Num83 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null){
            return null;
        }
        if(head.next ==null){
            return head;
        }
        ListNode dummyHead = new ListNode(0,head);
        ListNode prev = head;
        while(prev.next != null){
            if(prev.val == prev.next.val){
                prev.next = prev.next.next;
                continue;
            }else{
                prev = prev.next;
            }
        }
        return dummyHead.next;
    }
}